package com.gulimail.core.core.controller;

import com.gulimail.common.utils.PageUtils;
import com.gulimail.common.utils.R;
import com.gulimail.core.core.entity.MemberEntity;
import com.gulimail.core.core.feign.MemberOrders;
import com.gulimail.core.core.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;



/**
 * 
 *
 * @author hanzekun
 * @email hanzekuncs@gmail.com
 * @date 2020-06-28 10:53:34
 */
@RestController
@RequestMapping("core/member")
public class MemberController {
    @Autowired
    private MemberService memberService;
    @Autowired
    private MemberOrders memberOrders;

    /**
     *测试方法
     * /测试openfeign是否可以调用到订单(order)服务的接口
     */

    @RequestMapping("/MemberOrders")
    public R MemberOrders(){
        Map<String,Object> map = new HashMap<>();
        map.put("张三",0);
        R list = memberOrders.list(map);
        return list;
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("core:member:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("core:member:info")
    public R info(@PathVariable("id") Long id){
		MemberEntity member = memberService.getById(id);

        return R.ok().put("member", member);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("core:member:save")
    public R save(@RequestBody MemberEntity member){
		memberService.save(member);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("core:member:update")
    public R update(@RequestBody MemberEntity member){
		memberService.updateById(member);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("core:member:delete")
    public R delete(@RequestBody Long[] ids){
		memberService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
